using System.ComponentModel.DataAnnotations;
using MediatR;
using SmartTracking.Domain.HQX;
using SmartTracking.ErrorCode;

namespace BaseData.ReadApi.Appcontext.Command.Sheep_Records
{
    /// <summary>
    /// 羊只记录分页查询命令
    /// </summary>
    public class GetSheepRecordsPagedCommand : IRequest<ApiResult<ApiPaging<SheepRecords>>>
    {
        /// <summary>
        /// 当前页码
        /// </summary>
        [Required]
        [Range(1, int.MaxValue)]
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 每页记录数
        /// </summary>
        [Required]
        [Range(1, 100)]
        public int PageSize { get; set; } = 10;

        /// <summary>
        /// 验证命令参数
        /// </summary>
        /// <returns>验证结果</returns>
        public bool Validate(out string errorMessage)
        {
            errorMessage = string.Empty;

            if (PageIndex <= 0)
            {
                errorMessage = "页码必须大于0";
                return false;
            }

            if (PageSize <= 0 || PageSize > 100)
            {
                errorMessage = "每页记录数必须在1-100之间";
                return false;
            }

            return true;
        }
    }
}